package com.hr.controller.admin;

import com.hr.domain.dto.AddHouseImageDTO;
import com.hr.domain.po.HouseImage;
import com.hr.domain.query.HouseImagePageParams;
import com.hr.domain.query.HouseImagePageResult;
import com.hr.service.HouseImageService;
import com.hr.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin")
@Tag(name = "后台房屋照片信息管理")
@AllArgsConstructor
public class HouseImageController {

    private final HouseImageService houseImageService;

    /**
     * 分页获取房屋图片列表
     * @param queryParams
     * @return houseImagePageResult
     */
    @GetMapping("/house/image/pagelist")
    @Operation(summary = "分页获取房屋图片列表")
    public Result getHouseImagePageList(HouseImagePageParams queryParams) {
        log.info("分页获取房屋图片列表");
        HouseImagePageResult houseImagePageResult = houseImageService.getHouseImagePageList(queryParams);
        return Result.success(houseImagePageResult);
    }
    /**
     * 获取房屋图片排序序号
     * @param houseId
     * @return houseImageSortList
     */

    @GetMapping("/house/image/sort/{houseId}")
    @Operation(summary = "获取房屋图片排序序号")
    public Result getHouseImageSort(@PathVariable("houseId") Long houseId) {
        log.info("获取房屋图片排序序号");
        List<Integer> houseImageSortList = houseImageService.getSortOrder(houseId);
        return Result.success(houseImageSortList);
    }

    /**
     * 添加房屋图片
     * @param addHouseImageDTO
     * @return msg
     */
    @PostMapping("/house/image/add")
    @Operation(summary = "添加房屋图片")
    public Result addHouseImage(@RequestBody AddHouseImageDTO addHouseImageDTO) {
        log.info("添加房屋图片");
        String msg = houseImageService.addHouseImage(addHouseImageDTO);
        return Result.success(msg);
    }
    /**
     * 删除房屋图片
     * @param id
     * @return msg
     */
    @DeleteMapping("/house/image/delete/{id}")
    @Operation(summary = "删除房屋图片")
    public Result deleteHouseImage(@PathVariable("id") Integer id) {
        log.info("删除房屋图片");
        String msg = houseImageService.deleteHouseImage(id);
        return Result.success(msg);
    }
    /**
     * 批量删除房屋图片
     * @param ids
     * @return msg
     */
    @PostMapping("/house/image/delete/batch")
    @Operation(summary = "批量删除房屋图片")
    public Result deleteHouseImageBatch(@RequestBody List<Integer> ids) {
        log.info("批量删除房屋图片");
        String msg = houseImageService.deleteHouseImageBatch(ids);
        return Result.success(msg);
    }

}
